package com.example.orderminiappapi.tool;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class GetTime {
    public String getNowTime() {
        Date date = new Date();
        SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        return dateFormat.format(date);
    }

    public static String dateToStamp(String s) throws ParseException {
        String res;
        //设置时间模版
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = simpleDateFormat.parse(s);
        long ts = date.getTime();
        res = String.valueOf(ts);
        return res;
    }

    // 返回true是过期
    public Boolean ifOverDue(String s) throws ParseException {
        GetTime getTime = new GetTime();
        String createTime = getTime.getNowTime();
        Long time = (Long.parseLong(getTime.dateToStamp(createTime)) - Long.parseLong(getTime.dateToStamp(s)))/1000;
        return time > 15*60;
    }
}
